package JDBC;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;
//向数据库读取数据
public class Test1 {
    public static void main(String[] args) throws SQLException {
        Connection connectMysql = ConnectMysql.getConnectMysql();
        Statement statement = connectMysql.createStatement();
        ResultSet resultSet = statement.executeQuery("select * from user");
        List<User> users = new ArrayList<User>();
        while (resultSet.next()){
            User user = new User();
            user.setUserId(resultSet.getString("userId"));
            user.setName(resultSet.getString("name"));
            user.setEname(resultSet.getString("ename"));
            user.setPersonId(resultSet.getString("personId"));
            user.setSex(resultSet.getString("sex"));
            user.setCredit(resultSet.getInt("credit"));
            user.setCity(resultSet.getString("city"));
            users.add(user);
        }
        System.out.print(users);
        resultSet.close();
        statement.close();
        connectMysql.close();
    }
}
